<?php
	header("Content-Type: text/html;charset=utf-8");
	include("function/_nosql.php"); //
	include("function/function.php");
	include("_include.user.judge.php");
	$kboy_userid = $_SESSION['kboy_userid'];
	$kboy_user = $_SESSION['kboy_user'];
	$action = chkstr(trim($_REQUEST['action']));
	$strhtml = chkstr(trim($_REQUEST['strhtml']));
	$images = $_REQUEST['images'];
	$pid = chkstr(trim($_REQUEST['pid']));
	
	if($action == 'add'){
		if(!empty($images)){
			if(!is_array($images)){
				erro('参数错误');
			}
		}
		if(empty($strhtml)){
			erro('请输入评论内容');
		}
		$message_text = array('message_text'=>$strhtml,'images'=>$images);
		$message_text = json_encode($message_text);
		$message_text = str_replace("\\","\\\\",$message_text);
		
		$mysql = new sqlstr("kboy_forum_message"); 
		$mysql -> set("tid",$kboy_userid,true);
		$mysql -> set("message_text",$message_text);
		$add_sql = $mysql -> insertSql();
		$add_re = mysql_query($add_sql);
		if($add_re){
			re($_SERVER['HTTP_REFERER']);
		}else{
			erro('服务器内部错误');
		}
	}elseif($action == 'reply'){
		$message_text = $strhtml;
		if(strlen($message_text) < 1){
			erro('评论内容不能为空');
		}
		if(strlen($pid) < 1 || !isNumber($pid)){
			erro('参数错误');
		}
		
		if(getNewsNums('kboy_forum_message',"id=$pid") < 1){
			erro('参数错误');
		}
		
		$mysql = new sqlstr("kboy_forum_message"); 
		$mysql -> set("uid",$kboy_userid,true);
		$mysql -> set("pid",$pid,true);
		$mysql -> set("message_text",$message_text);
		$add_sql = $mysql -> insertSql();
		$add_re = mysql_query($add_sql);
		if($add_re){
			re($_SERVER['HTTP_REFERER']);
		}else{
			erro('服务器内部错误');
		}
		
	}else{
		erro("参数错误");
	}